package hbt;

import modelo.Coeficiente;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class HibernateCoeficienteDAO {

	private static HibernateCoeficienteDAO instancia = null;
	private static SessionFactory sf = null;

	public static HibernateCoeficienteDAO getInstancia() {
		if (instancia == null) {
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateCoeficienteDAO();
		}
		return instancia;
	}

	public void grabarCoeficiente(Coeficiente coe) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(coe);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void modificarCoeficiente(Coeficiente coe) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.update(coe);
		session.flush();
		session.getTransaction().commit();
		session.close();

	}

	public Coeficiente consultarCoeficiente(int id) {
		Session session = sf.openSession();
		Coeficiente coe = (Coeficiente) session.get(Coeficiente.class, id);
		session.close();
		return coe;
	}

}
